package cn.yuanqiao.archive.storeRoom.service.impl;

import cn.yuanqiao.archive.appManager.domain.DataScopeBase;
import cn.yuanqiao.archive.storeRoom.domain.PersonnelEntryExit;
import cn.yuanqiao.archive.storeRoom.mapper.PersonnelEntryExitMapper;
import cn.yuanqiao.archive.storeRoom.service.IPersonnelEntryExitService;
import cn.yuanqiao.common.exception.ServiceException;
import cn.yuanqiao.common.utils.DateUtils;
import cn.yuanqiao.common.utils.SnowflakeIdGenerator;
import cn.yuanqiao.common.utils.StringUtils;
import cn.yuanqiao.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 人员出入库Service业务层处理
 * 
 * @author xy
 * @date 2023-06-19
 */
@Service
public class PersonnelEntryExitServiceImpl implements IPersonnelEntryExitService
{
    @Autowired
    private PersonnelEntryExitMapper personnelEntryExitMapper;

    /**
     * 查询人员出入库
     * 
     * @param id 人员出入库主键
     * @return 人员出入库
     */
    @Override
    public PersonnelEntryExit selectPersonnelEntryExitByID(Long id)
    {
        String tenantCode = SecurityUtils.getTenantCode();
        if(StringUtils.isEmpty(tenantCode)) {
            throw new ServiceException("TenantCode is null");
           // return personnelEntryExitMapper.selectPersonnelEntryExitByID(id,"");
        }else{
            return personnelEntryExitMapper.selectPersonnelEntryExitByID(id,tenantCode.toUpperCase());

        }
    }

    /**
     * 查询人员出入库列表
     * 
     * @param personnelEntryExit 人员出入库
     * @return 人员出入库
     */
    @Override
    public List<PersonnelEntryExit> selectPersonnelEntryExitList(PersonnelEntryExit personnelEntryExit)
    {
        String tenantCode = SecurityUtils.getTenantCode();
        if(StringUtils.isEmpty(tenantCode)) {
            throw new ServiceException("TenantCode is null");
           // return personnelEntryExitMapper.selectPersonnelEntryExitList(personnelEntryExit,"");
        }else{
            return personnelEntryExitMapper.selectPersonnelEntryExitList(new DataScopeBase(),personnelEntryExit,tenantCode.toUpperCase());

        }
    }

    /**
     * 新增人员出入库
     * 
     * @param personnelEntryExit 人员出入库
     * @return 结果
     */
    @Override
    public int insertPersonnelEntryExit(PersonnelEntryExit personnelEntryExit)
    {
        personnelEntryExit.setCreateTime(DateUtils.getNowDate());
        personnelEntryExit.setCreator(SecurityUtils.getUserId());
        personnelEntryExit.setId(SnowflakeIdGenerator.generateId());
        personnelEntryExit.setIsDel(0);
        String tenantCode = SecurityUtils.getTenantCode();
        if(StringUtils.isEmpty(tenantCode)) {
            throw new ServiceException("TenantCode is null");
           // return personnelEntryExitMapper.insertPersonnelEntryExit(personnelEntryExit,"");
        }else{
            return personnelEntryExitMapper.insertPersonnelEntryExit(personnelEntryExit,tenantCode.toUpperCase());

        }
    }

    /**
     * 修改人员出入库
     * 
     * @param personnelEntryExit 人员出入库
     * @return 结果
     */
    @Override
    public int updatePersonnelEntryExit(PersonnelEntryExit personnelEntryExit)
    {
        personnelEntryExit.setLastUpdater(SecurityUtils.getUserId());
        personnelEntryExit.setLastupdateTime(DateUtils.getNowDate());
        String tenantCode = SecurityUtils.getTenantCode();
        if(StringUtils.isEmpty(tenantCode)) {
            throw new ServiceException("TenantCode is null");
           // return personnelEntryExitMapper.updatePersonnelEntryExit(personnelEntryExit,"");
        }else{
            return personnelEntryExitMapper.updatePersonnelEntryExit(personnelEntryExit,tenantCode.toUpperCase());

        }
    }

    /**
     * 批量删除人员出入库
     * 
     * @param ids 需要删除的人员出入库主键
     * @return 结果
     */
    @Override
    public int deletePersonnelEntryExitByIDs(Long[] ids)
    {
        String tenantCode = SecurityUtils.getTenantCode();
        if(StringUtils.isEmpty(tenantCode)) {
            throw new ServiceException("TenantCode is null");
           // return personnelEntryExitMapper.deletePersonnelEntryExitByIDs(ids,"");
        }else{
            return personnelEntryExitMapper.deletePersonnelEntryExitByIDs(ids,tenantCode.toUpperCase());
        }
    }

    /**
     * 删除人员出入库信息
     * 
     * @param id 人员出入库主键
     * @return 结果
     */
    @Override
    public int deletePersonnelEntryExitByID(Long id)
    {
        String tenantCode = SecurityUtils.getTenantCode();
        if(StringUtils.isEmpty(tenantCode)) {
            throw new ServiceException("TenantCode is null");
           // return personnelEntryExitMapper.deletePersonnelEntryExitByID(id,"");
        }else{
            return personnelEntryExitMapper.deletePersonnelEntryExitByID(id,tenantCode.toUpperCase());

        }
    }
}
